#include "T_MessageButtonDemo.h"

#include "ElaMessageButton.h"
#include "ElaScrollPageArea.h"
#include "ElaText.h"
#include "ElaToggleSwitch.h"

#include <QButtonGroup>
#include <QHBoxLayout>
#include <QVBoxLayout>

T_MessageButtonDemo::T_MessageButtonDemo(QWidget* parent)
    : T_BasePage(parent)
{
    // 预览窗口标题
    setWindowTitle("ElaMessageButtonDemo");

    // 顶部描述
    createCustomWidget("演示八个不同位置的弹窗按钮，点击按钮可在不同位置显示消息弹窗");

    // 创建八个不同位置的弹窗按钮
    _topButton = new ElaMessageButton("Top", this);
    _topButton->setBarTitle("顶部消息");
    _topButton->setBarText("这是一个显示在顶部的消息弹窗");
    _topButton->setMessageMode(ElaMessageBarType::Success);
    _topButton->setPositionPolicy(ElaMessageBarType::Top);

    _topLeftButton = new ElaMessageButton("TopLeft", this);
    _topLeftButton->setBarTitle("左上角消息");
    _topLeftButton->setBarText("这是一个显示在左上角的消息弹窗");
    _topLeftButton->setMessageMode(ElaMessageBarType::Information);
    _topLeftButton->setPositionPolicy(ElaMessageBarType::TopLeft);

    _topRightButton = new ElaMessageButton("TopRight", this);
    _topRightButton->setBarTitle("右上角消息");
    _topRightButton->setBarText("这是一个显示在右上角的消息弹窗");
    _topRightButton->setMessageMode(ElaMessageBarType::Success);
    _topRightButton->setPositionPolicy(ElaMessageBarType::TopRight);

    _bottomButton = new ElaMessageButton("Bottom", this);
    _bottomButton->setBarTitle("底部消息");
    _bottomButton->setBarText("这是一个显示在底部的消息弹窗");
    _bottomButton->setMessageMode(ElaMessageBarType::Warning);
    _bottomButton->setPositionPolicy(ElaMessageBarType::Bottom);

    _bottomLeftButton = new ElaMessageButton("BottomLeft", this);
    _bottomLeftButton->setBarTitle("左下角消息");
    _bottomLeftButton->setBarText("这是一个显示在左下角的消息弹窗");
    _bottomLeftButton->setMessageMode(ElaMessageBarType::Information);
    _bottomLeftButton->setPositionPolicy(ElaMessageBarType::BottomLeft);

    _bottomRightButton = new ElaMessageButton("BottomRight", this);
    _bottomRightButton->setBarTitle("右下角消息");
    _bottomRightButton->setBarText("这是一个显示在右下角的消息弹窗");
    _bottomRightButton->setMessageMode(ElaMessageBarType::Error);
    _bottomRightButton->setPositionPolicy(ElaMessageBarType::BottomRight);

    _leftButton = new ElaMessageButton("Left", this);
    _leftButton->setBarTitle("左侧消息");
    _leftButton->setBarText("这是一个显示在左侧的消息弹窗");
    _leftButton->setMessageMode(ElaMessageBarType::Warning);
    _leftButton->setPositionPolicy(ElaMessageBarType::Left);

    _rightButton = new ElaMessageButton("Right", this);
    _rightButton->setBarTitle("右侧消息");
    _rightButton->setBarText("这是一个显示在右侧的消息弹窗");
    _rightButton->setMessageMode(ElaMessageBarType::Success);
    _rightButton->setPositionPolicy(ElaMessageBarType::Right);

    // 创建滚动区域
    ElaScrollPageArea* messageButtonArea = new ElaScrollPageArea(this);
    QVBoxLayout* mainLayout = new QVBoxLayout(messageButtonArea);

    // 添加标题
    ElaText* titleText = new ElaText("ElaMessageButton - 位置演示", this);
    titleText->setTextPixelSize(18);
    titleText->setAlignment(Qt::AlignCenter);
    mainLayout->addWidget(titleText);
    mainLayout->addSpacing(20);

    // 第一行按钮：顶部位置
    ElaText* topRowText = new ElaText("顶部位置按钮:", this);
    topRowText->setTextPixelSize(15);
    mainLayout->addWidget(topRowText);
    
    QHBoxLayout* topRowLayout = new QHBoxLayout();
    topRowLayout->addWidget(_topButton);
    topRowLayout->addWidget(_topLeftButton);
    topRowLayout->addWidget(_topRightButton);
    topRowLayout->addStretch();
    mainLayout->addLayout(topRowLayout);
    mainLayout->addSpacing(15);

    // 第二行按钮：底部位置
    ElaText* bottomRowText = new ElaText("底部位置按钮:", this);
    bottomRowText->setTextPixelSize(15);
    mainLayout->addWidget(bottomRowText);
    
    QHBoxLayout* bottomRowLayout = new QHBoxLayout();
    bottomRowLayout->addWidget(_bottomButton);
    bottomRowLayout->addWidget(_bottomLeftButton);
    bottomRowLayout->addWidget(_bottomRightButton);
    bottomRowLayout->addStretch();
    mainLayout->addLayout(bottomRowLayout);
    mainLayout->addSpacing(15);

    // 第三行按钮：侧边位置
    ElaText* sideRowText = new ElaText("侧边位置按钮:", this);
    sideRowText->setTextPixelSize(15);
    mainLayout->addWidget(sideRowText);
    
    QHBoxLayout* sideRowLayout = new QHBoxLayout();
    sideRowLayout->addWidget(_leftButton);
    sideRowLayout->addWidget(_rightButton);
    sideRowLayout->addStretch();
    mainLayout->addLayout(sideRowLayout);
    mainLayout->addSpacing(15);

    // 添加禁用开关
    ElaText* disableText = new ElaText("禁用所有按钮:", this);
    disableText->setTextPixelSize(15);
    mainLayout->addWidget(disableText);
    
    QHBoxLayout* disableLayout = new QHBoxLayout();
    ElaToggleSwitch* disableSwitch = new ElaToggleSwitch(this);
    ElaText* disableLabel = new ElaText("禁用", this);
    disableLabel->setTextPixelSize(15);
    disableLayout->addWidget(disableSwitch);
    disableLayout->addWidget(disableLabel);
    disableLayout->addStretch();
    mainLayout->addLayout(disableLayout);

    // 连接禁用开关
    connect(disableSwitch, &ElaToggleSwitch::toggled, this, [=](bool checked) {
        _topButton->setDisabled(checked);
        _topLeftButton->setDisabled(checked);
        _topRightButton->setDisabled(checked);
        _bottomButton->setDisabled(checked);
        _bottomLeftButton->setDisabled(checked);
        _bottomRightButton->setDisabled(checked);
        _leftButton->setDisabled(checked);
        _rightButton->setDisabled(checked);
    });

    // 设置中心部件
    QWidget* centralWidget = new QWidget(this);
    QVBoxLayout* centerLayout = new QVBoxLayout(centralWidget);
    centerLayout->addWidget(messageButtonArea);
    centerLayout->setContentsMargins(0, 0, 0, 0);
    addCentralWidget(centralWidget, true, true, 0);
}

T_MessageButtonDemo::~T_MessageButtonDemo()
{
}